<head>
<title>hello</title>
<script>

var appdb;

function test(name)
{

try {
if (!window.openDatabase) {
alert('not supported');
} else {
var shortName = 'mydatabase';
var version = '1.0';
var displayName = 'My Important Database';
var maxSize = 65536; // in bytes
var mydb = openDatabase(shortName, version, displayName, maxSize);
// You should have a database instance in mydb.
}
} catch(e) {
// Error handling code goes here.
if (e == INVALID_STATE_ERR) {
// Version number mismatch.
alert("Invalid database version.");
} else {
alert("Unknown error "+e+".");
}
return;
}
//alert("Database is: "+mydb);
appdb=mydb;

createPeoplesTable(name);
}


function createTables()
{
var db=appdb;
/* To wipe out the table (if you are still experimenting with schemas,
   for example), enable this block. */
if (0) {
    db.transaction(
        function (transaction) {
        transaction.executeSql('DROP TABLE files;');
        transaction.executeSql('DROP TABLE filedata;');
        }
    );
}

db.transaction(
    function (transaction) {
        transaction.executeSql('CREATE TABLE IF NOT EXISTS files(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, filedata_id INTEGER NOT NULL, deleted INTEGER NOT NULL DEFAULT 0);', [], nullDataHandler, killTransaction);
        transaction.executeSql('CREATE TABLE IF NOT EXISTS filedata(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, datablob BLOB NOT NULL DEFAULT "");', [], nullDataHandler, errorHandler);

    }
);

alert("tables1");
db.transaction(
function (transaction) {
 transaction.executeSql('CREATE TABLE IF NOT EXISTS people(id INTEGER NOT NULL	PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL DEFAULT "John Doe", shirt TEXT NOT NULL DEFAULT "Purple");', [], nullDataHandler, errorHandler);
 transaction.executeSql('insert into people (name, shirt) VALUES ("Joe", "Green");', [], nullDataHandler, errorHandler);
 transaction.executeSql("SELECT * from people where shirt='Green';",[], dataHandler, errorHandler);
}
);
//alert("tables");
}

function createPeoplesTable(name)
{
  var db=appdb;
  db.transaction(
  function (transaction) {
  transaction.executeSql('CREATE TABLE IF NOT EXISTS people(id INTEGER NOT NULL	PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL DEFAULT "John Doe", shirt TEXT NOT NULL DEFAULT "Purple");', [], nullDataHandler, errorHandler);
}
);
insertPeoplesTable(name);
}

function insertPeoplesTable(name)
{

var db=appdb;
db.transaction(
function (transaction) {
 transaction.executeSql('insert into people (name, shirt) VALUES ('+'"'+name+'", "Green");', [], nullDataHandler, errorHandler);
}
);
selectPeoplesTable();
}

function selectPeoplesTable()
{
 var db=appdb;
  db.transaction(
  function (transaction) {
     transaction.executeSql("SELECT * from people where shirt='Green';",[], dataHandler, errorHandler);
    }
  );
}


function errorHandler(transaction, error)
{
    // Error is a human-readable string.
    alert('Oops.  Error was '+error.message+' (Code '+error.code+')');

    // Handle errors here
    var we_think_this_error_is_fatal = true;
    if (we_think_this_error_is_fatal) return true;
    return false;
}


function nullDataHandler(transaction, results)
{
}


function dataHandler(transaction, results)
{

  var string = "Green shirt list contains the following people:<br>";

   for (var i=0; i<results.rows.length; i++) {
       var row = results.rows.item(i);
       string = string + row['name'] + '<br>';
     }

document.getElementById('data').innerHTML=string;
}



</script>
</head>

<body>
<input type="text" name="appName" id="appName">
<input type="button" onclick="test(document.getElementById('appName').value)" value="test">
<p>
<div id="data"></div>
</body>